﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace NHL.App
{

    public partial class News : PhoneApplicationPage
    {
        public News()
        {
            InitializeComponent();
            WebClient twitter = new WebClient();
            twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
            twitter.DownloadStringAsync(new Uri("Http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=NHL"));
        }

        void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
        if (e.Error != null)
            return;

    XElement xmlTweets = XElement.Parse(e.Result);

    listBox1.ItemsSource = from tweet in xmlTweets.Descendants("status")
                            select new TwitterItem
                            {
                                ImageSource = tweet.Element("user").Element("profile_image_url").Value,
                                Message = tweet.Element("text").Value,
                                UserName = tweet.Element("user").Element("screen_name").Value,
                            };
        }
        
    }
    
    public class TwitterItem
    {
        public string UserName { get; set; }
        public string Message { get; set; }
        public string ImageSource { get; set; }
        public Uri Link { get; set; }
    }

}